/******************** 变量 ********************/
$checkbox-inner-width: 0.14rem;
$checkbox-inner-height: 0.14rem;

$radio-inner-width: 0.16rem;
$radio-inner-height: 0.16rem;

$checkbox-border-color: $border-color-secondary;
$checkbox-border-color-hover: $primary-color;
$checkbox-border-color-active: $primary-color;
$checkbox-border-color-selected: transparent;
$checkbox-button-default-border-color: transparent;
/******************** mixin ********************/

/******************** 组件 ********************/
.lv-checkbase {
  display: inline-flex;
  align-items: flex-start;
  font-size: 0;
  line-height: 1;
  cursor: pointer;

  >* {
    font-size: $font-size-base;
    line-height: $line-height-coeff;
  }

  >.lv-button {
    padding: 0 $padding-md;
  }

  .lv-checkbase-container {
    position: relative;
    margin-top: 0.03rem;

    &.lv-checkbase-container-hidden {
      width: 0;
      height: 0;
      overflow: hidden;
    }

    .lv-checkbase-input {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 100%;
      cursor: pointer;
      pointer-events: none;
      opacity: 0;

      &:disabled {
        cursor: not-allowed;
      }
    }
  }

  .lv-checkbase-label {
    // firefox升级到117版本后，width: calc(100% - 0.24rem)计算出来的宽度比116版本少了0.02px左右，会导致某些字符换行显示，比如Linux\Top 10
    // 0.24rem = 复选框的宽度0.16rem + 复选框和文字的间距0.08rem,chrome浏览器缩放后计算出来的宽度也会减少，和firefox类似，故使用0.23rem
    width: calc(100% - 0.23rem);
    margin-left: $margin-sm;
    color: $text-color;
    line-height: $line-height-base;
  }

  .lv-checkbox-inner,
  .lv-radio-inner {
    position: relative;
    display: block;
    white-space: normal;
    border: $border-width-base $border-style-base $checkbox-border-color;
  }

  .lv-radio-inner {
    width: $radio-inner-width;
    height: $radio-inner-height;
    border-radius: $border-radius-circle;

    @include motion-radio;
  }

  .lv-checkbox-inner {
    width: $checkbox-inner-width;
    height: $checkbox-inner-height;
    margin: 0.01rem; // checkbox 实际大小为16px，可显示内容区域为14px
    border-radius: $border-radius-base;

    @include motion-checkbox;
  }

  .lv-checkbox-inner-selected,
  .lv-radio-inner-selected {
    position: absolute;
    opacity: 0;
  }

  .lv-checkbox-inner-selected {
    top: 0;
    left: 0;
    display: block;
    color: $checkbox-selected-color;
    transform: scale(0.5);

    @include icon-size;

    .lv-icon-checked {
      vertical-align: baseline;
      position: absolute;
      left: 0;
      top: 0;
    }
  }

  .lv-radio-inner-selected {
    top: $space-base;
    left: $space-base;
    width: calc(#{$radio-inner-width} / 2);
    height: calc(#{$radio-inner-height} / 2);
    background: $checkbox-selected-color;
    border-radius: $border-radius-circle;
    transform: scale(0.5);

    @include motion-radio-inside;
  }

  &:hover:not([disabled]) {

    .lv-checkbox-inner,
    .lv-radio-inner {
      border-color: $checkbox-border-color-hover;
    }
  }

  &:active:not([disabled]) {

    .lv-checkbox-inner,
    .lv-radio-inner {
      border-color: $checkbox-border-color-active;
    }
  }

  &[disabled] {
    cursor: not-allowed;

    .lv-checkbox-inner,
    .lv-radio-inner {
      background: $disabled-background;
      border-color: $border-color-disabled;
    }

    .lv-checkbase-label {
      color: $text-color-disabled;
    }
  }

  &.lv-checkbase-no-label {
    align-items: center;

    .lv-checkbase-container {
      margin-top: 0;
    }
  }
}

// 选择按钮
.lv-checkbase {
  .lv-button {
    position: relative;
    color: $text-color;
    background-color: $input-background;
    border-color: $checkbox-border-color;
    border-left-width: 0;

    &.lv-button-type-default:not(.lv-button-loading) {
      border-right-width: 0;
      min-width: 0.95rem;

      &::before {
        position: absolute;
        top: 0;
        left: 0;
        display: block;
        box-sizing: content-box;
        border-left: 0.01rem solid $checkbox-border-color;
        height: 100%;
        content: '';
      }

      &:not(:disabled),
      &:not([disabled]) {
        &:hover {
          color: $text-color-link;
          background-color: $input-background;
          border-color: $checkbox-border-color;
          border-right-width: 0;
        }
      }

      &:disabled,
      &[disabled] {
        color: $text-color-disabled;
        background-color: $disabled-background;
        border-color: $checkbox-border-color;
      }
    }

    &.lv-button-type-link:not(.lv-button-loading) {
      color: $text-color-link;

      &:hover {
        color: $text-color-link;
      }

      &:disabled,
      [disabled] {
        color: $text-color-tertiary;
      }
    }
  }

  &:first-child {
    .lv-button {
      border-left-width: $border-width-base;

      &.lv-button-type-default:not(.lv-button-loading) {
        &::before {
          border-color: $checkbox-button-default-border-color;
        }
      }
    }
  }


  &:first-child:last-of-type,
  &:last-of-type:not(:first-child) {
    .lv-button.lv-button-type-default:not(.lv-button-loading) {
      border-right-width: 0.01rem;
      min-width: 0.96rem;

      &:hover {
        border-right-width: 0.01rem;
      }
    }
  }

  &:first-child:not(:last-of-type) {
    .lv-button {
      border-top-right-radius: $border-radius-none;
      border-bottom-right-radius: $border-radius-none;
    }
  }

  &:last-of-type:not(:first-child) {
    .lv-button {
      border-top-left-radius: $border-radius-none;
      border-bottom-left-radius: $border-radius-none;
    }
  }

  &:not(:first-child):not(:last-of-type) {
    .lv-button {
      border-radius: $border-radius-none;
    }
  }

  &.lv-checkbase-checked {

    &+.lv-checkbase-button .lv-button.lv-button-type-default:not(.lv-button-loading)::before,
    &+lv-tooltip+.lv-checkbase-button .lv-button.lv-button-type-default:not(.lv-button-loading)::before {
      border-color: $checkbox-border-color-active;
    }

    .lv-button.lv-button-type-default:not(.lv-button-loading) {

      &:not(:disabled),
      &:not([disabled]) {
        color: $text-color-link;
        border-color: $checkbox-border-color-active;

        &:hover {
          color: $primary-color-hover;
          border-color: $primary-color-hover;
        }
      }

      .lv-icon-host {
        color: currentcolor;
      }
    }

    &:not(:first-child) {
      .lv-button.lv-button-type-default:not(.lv-button-loading) {
        &::before {
          border-color: $checkbox-border-color-active;
        }

        &:disabled,
        &[disabled] {
          &::before {
            border-color: $border-color-disabled;
          }
        }
      }
    }
  }
}

// 选中
.lv-checkbase-checked {
  z-index: 3; // 配合group使用时的样式 ? TODO 为1会导致hover时候的样式不对

  .lv-checkbox-inner,
  .lv-radio-inner {
    background: $primary-color;
    border-color: $checkbox-border-color-selected;
  }

  .lv-checkbox-inner-selected,
  .lv-radio-inner-selected {
    opacity: 1;
  }

  .lv-checkbox-inner-selected {
    transform: scale(1);
  }

  .lv-radio-inner-selected {
    transform: rotate(0deg) scale(1) translate(0%, 0%);
  }

  &:hover:not([disabled]) {

    .lv-checkbox-inner,
    .lv-radio-inner {
      background: $primary-color-hover;
    }
  }

  &:active:not([disabled]) {

    .lv-checkbox-inner,
    .lv-radio-inner {
      background: $primary-color-active;
    }
  }

  &[disabled] {
    cursor: not-allowed;

    .lv-checkbox-inner,
    .lv-radio-inner {
      background: $disabled-background;
      border: $border-none;
    }

    .lv-checkbox-inner-selected {
      color: $checkbox-selected-color-disabled;
    }

    .lv-radio-inner-selected {
      background: $checkbox-selected-color-disabled;
    }
  }
}

// 半选
.lv-checkbox-indeterminate:not(.lv-checkbase-checked) {
  .lv-checkbox-inner {
    background: $primary-color;
    border: $border-none;
  }

  .lv-checkbox-inner-selected {
    top: 50%;
    left: 50%;
    width: 0.06rem;
    height: 0.06rem;
    margin-top: -0.03rem;
    margin-left: -0.03rem;
    background: $checkbox-selected-color;
    border: 0 $border-none;
    border-radius: $border-radius-xs;
    transform: rotate(0deg) scale(1) translate(0%, 0%);
    opacity: 1;

    @include motion-checkbox;

    i {
      display: none;
    }
  }

  &:hover:not([disabled]) {
    .lv-checkbox-inner {
      background: $primary-color-hover;
    }
  }

  &:active:not([disabled]) {
    .lv-checkbox-inner {
      background: $primary-color-active;
    }
  }

  &[disabled] {
    cursor: not-allowed;

    .lv-checkbox-inner {
      background: $disabled-background;
    }

    .lv-checkbox-inner-selected {
      background: $checkbox-selected-color-disabled;
    }
  }
}

.lv-group-row>.lv-checkbase.lv-checkbase-button.lv-group-border-overlap {
  margin-right: 0;
}